<%@page language="java"  pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="java.util.Date"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires", 0); response.flushBuffer();
%>
<html class="pixel-ratio-2 retina ios ios-9 ios-9-1 ios-gt-8 ios-gt-7 ios-gt-6 watch-active-state">

<HEAD>
	<TITLE>支付</TITLE>
	<BASE href="<%=basePath%>">
	<META content="IE=10.000" http-equiv="X-UA-Compatible">
	<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<META http-equiv="X-UA-Compatible" content="IE=edge">
	<META name="apple-mobile-web-app-status-bar-style" content="black">
	<META name="GENERATOR" content="MSHTML 10.00.9200.17296">
	<META name="format-detection" content="telephone=no">
	<META http-equiv="pragma" content="no-cache">
	<META http-equiv="cache-control" content="no-cache">
	<META http-equiv="expires" content="0">
	<META content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/f7/framework7.ios.min.css"  type="text/css" />
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/f7/framework7.ios.colors.min.css" type="text/css" />
	<SCRIPT type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.10.2.min.js"></SCRIPT>
	<script type="text/javascript" src='${pageContext.request.contextPath}/js/f7/framework7.js'></script>
	<script type="text/javascript" src='${pageContext.request.contextPath}/js/f7/framework7.min.js'></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<style type="text/css">
	*{   
    -webkit-touch-callout:none;  /*系统默认菜单被禁用*/   
    -webkit-user-select:none; /*webkit浏览器*/   
    -khtml-user-select:none; /*早期浏览器*/   
    -moz-user-select:none;/*火狐*/   
    -ms-user-select:none; /*IE10*/   
    user-select:none;   
}  
	</style>

	<SCRIPT type="text/javascript">
		$(document).ready(function(){
			var agentUrl='${pageContext.request.contextPath}'+"/image/logo/"+'${customer.agent.id}'+"-adv.png";
			var defaulUrl='${pageContext.request.contextPath}'+"/image/f7/0title.png";
			  var ImgObj = new Image(); //判断图片是否存在  
			  ImgObj.src = agentUrl;  
			  //没有图片，则返回-1
			  var wi=ImgObj.width;
			  var he=ImgObj.height;
			  if (wi > 0 && he > 0) { 
			    $("#advLogo").html("<img src='"+agentUrl+"' width='100%' height='100%'/>");
			    
			  } else {
			  	$("#advLogo").html("<img src='"+defaulUrl+"' width='100%' height='100%'/>");	
			  }
		});
		
	var myApp = new Framework7();
    function numberChange(val){
        if('C'==val){
            document.getElementById("showmoney").innerText="0";
            return;
        }
        if('D'==val){
            var amount = document.getElementById("showmoney").innerText;
            var length = amount.length;
            if (length == 1){
                document.getElementById("showmoney").innerText="0";
                var ddd=document.getElementById("buttonpay"); 
				ddd.style.cssText="background:#e2e2e2;border-radius: 5px;";
                return;
            }
            if (length > 1) {
             document.getElementById("showmoney").innerText=amount.substring(0, length-1);
            }
            return;
        }
        
        var ddd=document.getElementById("buttonpay"); 
		ddd.style.cssText="background:#d8effe;border-radius: 5px;";
        if(parseInt(document.getElementById("showmoney").innerText)>9999999){
            myApp.alert("<div style='text-align:center;'>输入金额值超限,请重新输入</div>", "提示");
            return;
        }
        if(document.getElementById("showmoney").innerText=='0'||document.getElementById("showmoney").innerText=='00'){
            if(val=='.'){
                document.getElementById("showmoney").innerText+=val;
            }else{
                document.getElementById("showmoney").innerText="";
                if(!("C"==val)){
                    document.getElementById("showmoney").innerText+=val;
                }else{
                    document.getElementById("showmoney").innerText="0";
                }               
            }
        }else{
            var money = document.getElementById("showmoney").innerText;
            if(money.indexOf('.')>0){
                if(val=='.'){
                    return;
                }
                if(money.split(".")[1].length>1){
                    return;
                }                   
            }
            document.getElementById("showmoney").innerText+=val; 
        }
    }
    function updatedis(){
    	var btn = document.getElementById('buttonpay');
    	document.getElementById("showmoney").innerText=0;
    	btn.disabled = false;
    }
    function submitAmount(){
     	$("#buttonpay").attr("disabled","disabled");
     	  setTimeout('updatedis()',5000);
        var ddd=document.getElementById("buttonpay");
		ddd.style.cssText="background:#e2e2e2;border-radius: 5px;";
		var amount = parseFloat(document.getElementById("showmoney").innerText);
		if ((isNaN(amount))||( amount == 0)){
            myApp.alert("<div style='text-align:center;'>请录入付款金额</div>", "提示");
            return;
        }
		$("#amt").val(amount);
		if (navigator.onLine) {
            var basePath = $("#basePath").val();
            var userId = $("#userId").val();
			var openId= $("#openId").val();
			var code = $("#code").val();
			var amt= $("#amt").val();
	    	$.post(
	    		basePath + 'trans/officialAccPay.action',
				{userId:userId,payType:2,amt:amt,openId:openId,code:code},
				function (data) {
					var json=eval("("+data+")");
					if('0'==json.code){
						$("#orderId").val(json.orderId);
						$("#externalId").val(json.externalId);
	            		jsApiCall(json);
	            	}else{
	            		 alert(json.msg);
	            	}
	         	}
	         );
      	} else {
          myApp.alert("<div style='text-align:center;'>网络状况不佳，请稍后再试或使用其他支付方式</div>", "提示");
		}
    }
    
	$(function(){
	    $("#cusCenterBtn").click(function(){
	     	$('body').append('<form id="goManage" action="customerRegisterManage.action" method="post" data-ajax="false"></form>');
	    	$("#goManage").submit();
	    	 
	    });
	});	
	function jsApiCall(json){
  			WeixinJSBridge.invoke(
				'getBrandWCPayRequest',{
					"appId" : json.appId, //公众号名称，由商户传入
					"timeStamp": json.timestamp, //时间戳，自1970 年以来的秒数
					"nonceStr" : json.nonceStr, //随机串
					"package" : json.prepayId,
					"signType" : "MD5", //微信签名方式:
					"paySign" : json.paySign  //微信签名,
				},function(res){
                    alert(res.err_msg);
					if(res.err_msg == "get_brand_wcpay_request:ok" ) {
						// 此处可以使用此方式判断前端返回,微信团队郑重提示：res.err_msg 将在用户支付成功后返回ok，但并不保证它绝对可靠，。
						$("#formData").submit();
					}
				}
			);
		}
	</SCRIPT>
</HEAD>

<BODY>
<!-- 	<s:set name="entity" value="#attr['customer'].list[0]" /> -->
    <input type="hidden" id="basePath" value="<%=basePath%>"/>
	<form data-role="none" id="formData" method="post" data-ajax="false" onsubmit="return submitAmount();" action="customerRegisterPaySuccess.action">
		<div class="wrapper">
			<div data-role="header" style="background-color:#d8effe;height:25%;" id="advLogo">
				<img src="${pageContext.request.contextPath}/image/f7/0title.png" width="100%" height="100%"/>
 			</div>
		    <div class="margin-cuFuNa" >
		    	<span class="font20 margin-left20" >${fullName}</span>
			</div>
		<div class="margin-money" >
			<span class="font18 margin-left20">付款金额</span>
			<span style="float: right;margin: 0px 20px 0px 0px;" >
				<button type="button" class="cum-btn" id="cusCenterBtn">商户管理</button>
			</span>
		</div>
		    <div class="pub-bg money-num margin-top" >
		        <span class="fcolor1 font18 float-left selfS">￥</span>
		        <div class="fcolor1 font40" id="showmoney">0</div>
		    </div>
		<p style="float: right;margin: 4% 0PX 0PX 0PX;"><a href="#" style="color:#979595" class="open-popup">操作指引</a></p>
		<div class="keyboard"> 
 			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button1" onclick="numberChange('1');">1</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button2" onclick="numberChange('2');">2</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button3" onclick="numberChange('3');">3</button>
			    <button type="button" class="button num-btn" style="border-radius: 5px;border:1px solid #e2e2e2;height:56px;" id="buttonDel" onclick="numberChange('D');"><img src="${pageContext.request.contextPath}/image/f7/09delete.png" width="40px"></button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;"id ="button4" onclick="numberChange('4');">4</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button5" onclick="numberChange('5');">5</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button6" onclick="numberChange('6');">6</button>
<!-- 			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" style="color:#ff9502;" id ="buttonC" onclick="numberChange('C');">C</button> -->
				<button type="button" class="num-btn" style="height:56px;" >&nbsp;</button>
				<button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button7" onclick="numberChange('7');">7</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button8" onclick="numberChange('8');">8</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button9"onclick="numberChange('9');">9</button>
			    <button type="button" class="num-btn" style="height:56px;" >&nbsp;</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button00" onclick="numberChange('00');">00</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="button0" onclick="numberChange('0');">0</button>
			    <button type="button" class="button num-btn" style="border:1px solid #e2e2e2;color:#535353;font-size:25px;height:56px;" id ="buttondot" onclick="numberChange('.');">.</button>
			    <button  type="button" class="pay-btn"id ="buttonpay" onclick="submitAmount();">确认<BR/>支付</button>
		 </div>
		<div class="popup popup-about">
			<div class="view navbar-fixed">
				<div class="pages">
					<div class="page">
						<div class="navbar">
							<div class="navbar-inner">
					    		<div class="center">操作指引</div>
						        <div class="right"><a href="#" class="link close-popup">确认</a></div>
					         </div>
					    </div>
						<div class="page-content">
						     <img src="${pageContext.request.contextPath}/image/f7/wechatPay1.png" style="width:99%; padding-left:1px;"/>
						 </div>
					</div>
				</div>
			</div>
		</div> 
		
		</div>
		<input type="hidden" id="externalId" name="externalId" >
		<input type="hidden" id="code" name="code" value="${code}">
		<input type="hidden" id="userId" name="id" value="${userId}">
		<input type="hidden" id="openId" name="openId" value="${openId}">
		<input type="hidden" id="orderId" name="orderId" value="">
		<input type="hidden" id="amt" name="amt">
			      
	</form>

</BODY>
</html>